package handler.bid

import util.Utils
import util.IntervalUtils

import service.CardService
import service.QrService

// 企业打卡的二维码图片生成，定时任务
handler.get('schedule-qrcode-image-generate'){tmp, tmp2 ->
	final String KEY = 'qrcode-image-generate'

	// 一分钟一次
	long interval = 60000
	if(!IntervalUtils.needRefresh(KEY, interval))
		return

	log.info(KEY + ' begin')

	def list = CardService.getScanerIdList()
	for(one in list){
		String token = Utils.uuid()
		String content = CardService.urlSwipeCard + '?scanerId=' + one.id + '&token=' + token

		String filePath = config.webroot + '/qr/' + one.id + '.png'
		QrService.output(content, filePath, 300, 300)

		CardService.updateScanerToken(one.id, token)

		log.info('update scaner token ok - ' + one.id)
	}
	log.info(KEY + ' end')

	handlerSockjs.broadcast('scanerQrRefreshed')

	return null
}